package com.copm.ifm.common.redis;

/**
 * redis键工具类
 *
 * @author zzf
 * @date 2020/12/22 9:34
 */
public class RedisKeyHelper {

    /**
     * 默认拼接字符
     */
    private static final String SPLIT_CHAR = ":";

    /*========================LEVEL 1============================*/
    /**
     * 系统
     */
    private static final String SYS = "sys:";
    /**
     * 用户
     */
    private static final String USER = "user:";



    /*========================LEVEL 2============================*/
    /**
     * 字典
     */
    private static final String DICT = "dict:";
    /**
     * 租户
     */
    private static final String TENANT = "tenant:";
    /**
     * token
     */
    private static final String TOKEN = "token:";
    /**
     * 角色
     */
    private static final String ROLE = "role:";
    /**
     * 菜单
     */
    private static final String MENU = "menu:";
    /**
     * 菜单
     */
    private static final String STAFF = "staff:";

    /*========================LEVEL 3+============================*/


    /*=========SYS ABOUT BEGIN===========*/

    /**
     * 获取系统数据字典键
     */
    public static String sysDict(String dictCode) {
        return SYS + DICT + dictCode;
    }

    /**
     * 获取租户数据字典键
     * <p>
     * 形成的redis架构如下：
     * sys:__
     * .....|_dict:__SYS_DICT_CODE1__key1:DictContentBO1
     * ...........|...............|__key2:DictContentBO2
     * ...........|
     * ...........|__SYS_DICT_CODE2__key1:DictContentBO1
     * ...........|...............|__key2:DictContentBO2
     * ...........|
     * ...........|_tenant:__
     * .....................|_TENANT_ID1:__SYS_DICT_CODE1__key3:DictContentBO3
     * .....................|...........|...............|__key4:DictContentBO4
     * .....................|...........|
     * .....................|...........|__SYS_DICT_CODE2__key5:DictContentBO5
     * .....................|...........................|__key6:DictContentBO6
     * .....................|
     * .....................|_TENANT_ID2:__SYS_DICT_CODE1__key3:DictContentBO3
     * .................................|...............|__key4:DictContentBO4
     * .................................|
     * .................................|__SYS_DICT_CODE2__key5:DictContentBO5
     * .................................................|__key6:DictContentBO6
     */
    public static String sysTenantDict(Long tenantId, String code) {
        return SYS + DICT + TENANT + tenantId + SPLIT_CHAR + code;
    }

    /**
     * 获取用户权限信息字典键
     */
    public static String sysMenu(String menuCode) {
        return SYS + MENU + menuCode;
    }

    /**
     * 获取用户权限信息字典键
     */
    public static String tenantMenu(Long tenantId, String menuCode) {
        return SYS + MENU + TENANT + tenantId + SPLIT_CHAR + menuCode;
    }
    /*=========SYS ABOUT END===========*/


    /*=========USER ABOUT BEGIN===========*/

    /**
     * 获取用户token字典键
     */
    public static String token(String key) {
        return USER + TOKEN + key;
    }

    /**
     * 获取用户token字典键
     */
    public static String token(Long key) {
        return USER + TOKEN + key;
    }

    /**
     * 获取用户权限信息字典键
     */
    public static String role(Long userId) {
        return USER + ROLE + userId;
    }

    /**
     * 获取用户权限信息字典键
     */
    public static String userMenu(Long userId) {
        return USER + MENU + userId;
    }

    public static String getStaffNameById(Long staffId) {
        return SYS + STAFF + staffId;
    }

    /*=========USER ABOUT END===========*/

}
